import BaseTan from '../../../_resource/common/modules/JiessDialog/BaseTan.js'
class Tan extends BaseTan {
	static tanInstance(...args) {
		return Tan.initInstance(new Tan(...args));
	}
	initOpen({
		title,
		buttons,
		children,
		width = 960,
		hasButtons = true,
		initButtons,
		...param
	}) {
		const { exec, instance, ActionButtons } = this;
		instance().open(function(show) {
			const close = () => show.value = false;
			buttons = exec(buttons, [close, show]);
			return {
				title,
				width,
				$slots: {
					default: exec(children, [close, show]),
					footer() {
						return hasButtons ? {
							is: ActionButtons,
							buttons: () => buttons ? buttons : initButtons.call(this, close)
						} : [];
					}
				},
				...param
			};
		});
	}
	open({ onOk, onCancel, okText = '确定', cancelText = '取消', ...param }) {
		const click = this.onClick;
		this.initOpen({
			...param,
			initButtons(close) {
				return [{
						text: okText,
						type: 'primary',
						onClick: click(this, onOk, close)
					},
					{
						text: cancelText,
						onClick: click(this, onCancel, close)
					}
				]
			}
		})
	}
	// 默认为一个关闭按钮的弹框，但可以自定义配置多个按钮
	alert({ initButtons, onClose, ...param }) {
		const click = this.onClick;
		this.initOpen({
			...param,
			initButtons(close) {
				return [{
					text: '关闭',
					type: 'primary',
					onClick: click(this, onClose, close)
				}]
			}
		})
	}
}
// ----------------------------------------
export default Tan.tanInstance;